package org.c41.graphics.effect;

import java.awt.Image;

import org.c41.graphics.Bounds;
import org.c41.graphics.C41Graphic;
import org.c41.util.Check;

public abstract class BoundsEffect extends Effect {

	private Image image;
	private Bounds bounds;
	private long current_time;
	
	public BoundsEffect(Image image){
		Check.notNull(image);
		this.image=image;
		this.bounds=new Bounds(0,0,image.getWidth(null),image.getHeight(null));
	}
	
	@Override
	public int getWidth() {
		return image.getWidth(null);
	}

	@Override
	public int getHeight() {
		return image.getHeight(null);
	}

	@Override
	public void updateEffect(long during) {
		current_time+=during;
		updateBounds(current_time, bounds);
	}

	protected abstract void updateBounds(long current, Bounds bounds);

	@Override
	public void paintReady(C41Graphic g) {
		g.drawImage(image, 0, 0, image.getWidth(null), image.getHeight(null));
	}

	@Override
	public void paintEffect(C41Graphic g) {
		g.drawImage(image, bounds.x, bounds.y, bounds.width, bounds.height);
	}

	@Override
	public void paintCompleted(C41Graphic g) {
		g.drawImage(image, 0, 0, image.getWidth(null), image.getHeight(null));
	}

	@Override
	public void complete(){
		super.complete();
		this.current_time=0L;
	}
	
}
